﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.Domain.Entities;
using ITProject.Repository.Abstract;
using System.ComponentModel.DataAnnotations;

namespace ITProject.WebUI.Models.Project
{

    /// <summary>
    /// Klasa modelu widokowego wyświetlania informacji o konkretnym projekcie.
    /// Autor: Jakub Szatkowski
    /// </summary>
    public class ProjectProjectViewModel
    {
        public string LogoPath { get; set; }
        public string Name { get; set; }
        public string ShortDescription { get; set; }
        public string Description { get; set; }
        [DataType(DataType.Date)]
        public DateTime StartDate { get; set; }
        public List<ProjectCommentViewModel> comment { get; set; }
        public ProjectMenuViewModel MenuViewModel { get; set; }
        public ProjectCommentViewModel newComment { get; set; }

        static string defaultlogo = "default_logo.png";

        /// <summary>
        /// Metoda statyczna konwertujaca projekt i repozytorium projektu do pobrania danych z bazy na model widokowy proejktu.
        /// Autor: Jakub Szatkowski
        /// </summary>
        /// <param name="project">Projekt.</param>
        /// <returns>Model widokowy projektu.</returns>
        public static ProjectProjectViewModel Convert(ITProject.Domain.Entities.Project project,Comment[] comments,User[] users)
        {
            ProjectProjectViewModel viewModel = new ProjectProjectViewModel();
            viewModel.Name = project.Name;
            viewModel.newComment = new ProjectCommentViewModel();
            string logoPath = defaultlogo;
            if (project.LogoPath != null)
                logoPath = project.LogoPath;
            viewModel.LogoPath = logoPath;
            viewModel.ShortDescription = project.ShortDescription;
            viewModel.Description = project.Description;
            viewModel.StartDate = project.StartDate;
            viewModel.comment = new List<ProjectCommentViewModel>();
            ProjectCommentViewModel cs;
            foreach (Comment c in comments)
            {
                cs=new ProjectCommentViewModel();
                cs.datetime=c.datetime;
                cs.Text=c.Text;
                cs.UserName=users.Where(X=>X.Id==c.Id_User).First().Login;
                viewModel.comment.Add(cs);

            }
            return viewModel;
        }
    }
}